# app/core/config.py

# 修改后的代码
# from pydantic_settings import BaseSettings
from pydantic import BaseSettings
import os
from dotenv import load_dotenv
from app.core.logging_config import get_internal_logger

internal_logger = get_internal_logger()

# 加载环境变量
load_dotenv(override=True)

# 判断项目根目录是否存在.env文件
# 如果存在，则加载环境变量
if os.path.exists('.env'):
    load_dotenv(override=True)
else:
    internal_logger.error("未找到.env文件，请检查是否存在")
    raise Exception("未找到.env文件，请检查是否存在")


# 通过环境来区分密码
ENVIRONMENT = os.getenv('ENVIRONMENT')
internal_logger.info(f"环境: {ENVIRONMENT}")

class Settings(BaseSettings):
    API_PREFIX_V1: str = "/api/v1"
    PROJECT_NAME: str = "LuZhuoAI"

    # V2版本数字人API配置
    EXTERNAL_API_V2_URL: str = 'https://s-ql.luzhuofun.com:7050/person/create'
    EXTERNAL_API_V2_AUTH: str = os.environ.get('EXTERNAL_API_V2_AUTH', 'fc8404343ab4564607dd')
    EXTERNAL_API_V2_PLATFORM: str = 'novo'

    # V2版本声音克隆API配置
    EXTERNAL_VOICE_V2_URL: str = 'https://s-ql.luzhuofun.com:7050/voice/create'
    EXTERNAL_VOICE_V2_AUTH: str = os.environ.get('EXTERNAL_VOICE_V2_AUTH', 'fc8404343ab4564607dd')
    EXTERNAL_VOICE_V2_PLATFORM: str = 'novo'
    EXTERNAL_VOICE_V2_TYPE: str = os.environ.get('EXTERNAL_VOICE_V2_TYPE', 'lite')  # 可配置的voiceType

    # V2版本作品创建API配置
    EXTERNAL_VIDEOMIX_V2_URL: str = 'https://s-ql.luzhuofun.com:7050/videomix/create'
    EXTERNAL_VIDEOMIX_V2_AUTH: str = os.environ.get('EXTERNAL_VIDEOMIX_V2_AUTH', 'fc8404343ab4564607dd')
    EXTERNAL_VIDEOMIX_V2_PLATFORM: str = 'novo'

    # MySQL 数据库配置
    MYSQL_HOST: str = 'localhost'
    MYSQL_PORT: int = 3306
    MYSQL_USER: str = 'root'
    # 通过环境来区分密码
    if ENVIRONMENT == 'dev':
        MYSQL_PASSWORD: str = 'ma180821'
    else:
        MYSQL_PASSWORD: str = '842523563'
    MYSQL_DB: str = 'luzhuointernal'

    # TOS视频文件位置
    OSS_VIDEO_TASK : str = 'luzhuointernal'
    OSS_VIDEO_URL : str = 'shuzhiren'
    OSS_AUDIO_URL : str = 'yinpin'
    OSS_ACCESS_AK : str = 'AKLTODc3Y2IyMDM4ZjU4NDg2N2JkYTJlNjY0ZWVkZmYyOTg'
    OSS_ACCESS_SK : str = 'TlRZNE1qQmlNVE5oWm1FNE5ETTBabUkwWWpJNU56bG1OR001WVdSaU5qVQ=='
    TOS_RoleTrn : str = 'trn:iam::2100903486:role/sts'

    # V2版本回调地址配置
    V2_CALLBACK_URL = os.environ.get('V2_CALLBACK_URL', 'https://hwserver.luzhuofun.com:8080')
    V2_VOICE_CALLBACK_URL = os.environ.get('V2_VOICE_CALLBACK_URL', 'https://hwserver.luzhuofun.com:8080/api/v2/voice/callback')
    V2_VIDEOMIX_CALLBACK_URL = os.environ.get('V2_VIDEOMIX_CALLBACK_URL', 'https://hwserver.luzhuofun.com:8080/api/v2/videomix/callback')
    
    # 内部API回调地址配置（无需token验证的内部接口）
    if ENVIRONMENT == 'dev':
        INTERNAL_CALLBACK_BASE_URL = os.environ.get('INTERNAL_CALLBACK_BASE_URL', 'https://c15185d29b1b.ngrok-free.app') # 开发环境(windows)回调地址
    else:
        INTERNAL_CALLBACK_BASE_URL = os.environ.get('INTERNAL_CALLBACK_BASE_URL', 'https://hwserver.luzhuofun.com:8090') # 生产环境(linux)回调地址
    INTERNAL_VIDEO_CALLBACK_URL = f"{INTERNAL_CALLBACK_BASE_URL}/api/v1/internal/callback/video" # 内部数字人回调地址
    INTERNAL_VIDEOMIX_CALLBACK_URL = f"{INTERNAL_CALLBACK_BASE_URL}/api/v1/internal/callback/videomix" # 内部作品回调地址
    INTERNAL_VOICE_CALLBACK_URL = f"{INTERNAL_CALLBACK_BASE_URL}/api/v1/internal/callback/voice" # 内部声音回调地址

    # jwt配置
    SECRET_KEY = os.environ.get('SECRET_KEY', 'FJPnG0A2LsdyLgwO4KWHAAAAFmdvbmdsaUBERVNLVE9QLVFJSEM0VTUBAgMEBQYH') # jwt秘钥
    ALGORITHM = "HS256" # jwt算法

    # 公共声音
    GONGGONG_AUDIO_URL ={
        "code": 200,
        "type": 2,
        "data": [
            {
                "voice_id": "6d69e724-f0c9-4598-bfa9-52d555260d64",
                "type": 10,
                "title": "热情甜美",
                "audio_url":"https://luzhuoai.tos-cn-beijing.volces.com/audio_url/%E7%83%AD%E6%83%85%E7%94%9C%E7%BE%8E.wav"
            },
            {
                "voice_id": "5be90bf3-e222-4b63-bab2-73fe16364bd2",
                "type": 10,
                "title": "儒雅哲学",
                "audio_url":"https://luzhuoai.tos-cn-beijing.volces.com/audio_url/%E5%84%92%E9%9B%85%E5%93%B2%E5%AD%A6.wav"
            },
            {
                "voice_id": "db81e1e3-1d32-43e0-b4fd-456155563f09",
                "type": 10,
                "title": "亲切女声",
                "audio_url": "https://luzhuoai.tos-cn-beijing.volces.com/audio_url/%E4%BA%B2%E5%88%87%E5%A5%B3%E7%94%9F.wav"
            },
            {
                "voice_id": "6c9c106b-3629-4ca4-8b93-2c46b673d23c",
                "type": 10,
                "title": "黑土 东北老铁",
                "audio_url": "https://luzhuoai.tos-cn-beijing.volces.com/audio_url/%E9%BB%91%E5%9C%9F%20%E4%B8%9C%E5%8C%97%E8%80%81%E9%93%81.wav"
            },
            {
                "voice_id": "2043e8df-acfa-4c91-8cd0-173c03a29cfa",
                "type": 10,
                "title": "锅锅 重庆小伙",
                "audio_url": "https://luzhuoai.tos-cn-beijing.volces.com/audio_url/%E9%94%85%E9%94%85%20%E9%87%8D%E5%BA%86%E5%B0%8F%E4%BC%99.wav"
            },
            {
                "voice_id": "c98526c7-651a-4767-b529-ab419134bee8",
                "type": 10,
                "title": "聚贤 广西老表",
                "audio_url": "https://luzhuoai.tos-cn-beijing.volces.com/audio_url/%E8%81%9A%E8%B4%A4%20%E5%B9%BF%E8%A5%BF%E8%80%81%E8%A1%A8.wav"
            },
            {
                "voice_id": "7a387b1b-b21b-40b1-ab26-aec3478431f6",
                "type": 10,
                "title": "晓敏 粤语女声",
                "audio_url":"https://luzhuoai.tos-cn-beijing.volces.com/audio_url/%E6%99%93%E6%95%8F%20%E7%B2%A4%E8%AF%AD%E5%A5%B3%E5%A3%B0.wav"
            },
            {
                "voice_id": "c9f3fe5d-69db-4fb6-929b-bf9ec0cb2e0a",
                "type": 10,
                "title": "晓海 粤语男声",
                "audio_url":"https://luzhuoai.tos-cn-beijing.volces.com/audio_url/%E6%99%93%E6%B5%B7%20%E7%B2%A4%E8%AF%AD%E7%94%B7%E5%A3%B0.wav"
            },
            {
                "voice_id": "f9f0b743-e295-42b9-a312-ac8bcc67263e",
                "type": 10,
                "title": "通用女声",
                "audio_url":"https://luzhuoai.tos-cn-beijing.volces.com/audio_url/%E9%80%9A%E7%94%A8%E5%A5%B3%E5%A3%B0.wav"
            },
            {
                "voice_id": "ac5af1cf-8f70-463b-bdd5-25fe465d4a17",
                "type": 10,
                "title": "通用男声",
                "audio_url":"https://luzhuoai.tos-cn-beijing.volces.com/audio_url/%E9%80%9A%E7%94%A8%E7%94%B7%E5%A3%B0.wav"
            },
            {
                "voice_id": "d4f4b1cd-4fc0-407a-ba09-336c07dd7ae8",
                "type": 10,
                "title": "儒雅青年",
                "audio_url":"https://luzhuoai.tos-cn-beijing.volces.com/audio_url/%E9%94%85%E9%94%85%20%E9%87%8D%E5%BA%86%E5%B0%8F%E4%BC%99.wav"
            },
            {
                "voice_id": "0cd03904-88df-47da-8312-aeb91a820520",
                "type": 10,
                "title": "古风少御",
                "audio_url": "https://luzhuoai.tos-cn-beijing.volces.com/audio_url/%E5%8F%A4%E9%A3%8E%E5%B0%91%E5%BE%A1.wav"
            },
            {
                "voice_id": "13bc0b88-3c85-4990-b450-fc1307d99b5a",
                "type": 10,
                "title": "阳光男孩",
                "audio_url":"https://luzhuoai.tos-cn-beijing.volces.com/audio_url/%E9%98%B3%E5%85%89%E7%94%B7%E5%AD%A9.wav"
            },
            {
                "voice_id": "c0de9ddc-9ab7-4f15-8c72-d834c97229e2",
                "type": 10,
                "title": "青春热情",
                "audio_url":"https://luzhuoai.tos-cn-beijing.volces.com/audio_url/%E9%9D%92%E6%98%A5%E7%83%AD%E6%83%85.wav"
            },
            {
                "voice_id": "300c1c3b-7012-48f3-b97b-9c61e6ec1245",
                "type": 10,
                "title": "卖场直播",
                "audio_url": "https://luzhuoai.tos-cn-beijing.volces.com/audio_url/%E5%8D%96%E5%9C%BA%E7%9B%B4%E6%92%AD.wav"
            },
            {
                "voice_id": "b21d550d-b968-4d58-b421-2074894f4074",
                "type": 10,
                "title": "青年男声",
                "audio_url": "https://luzhuoai.tos-cn-beijing.volces.com/audio_url/%E9%9D%92%E5%B9%B4%E7%94%B7%E5%A3%B0.wav"
            },
            {
                "voice_id": "a7fd1bc2-3955-4665-95d3-6cb208571708",
                "type": 10,
                "title": "利落冷静",
                "audio_url": "https://luzhuoai.tos-cn-beijing.volces.com/audio_url/%E5%88%A9%E8%90%BD%E5%86%B7%E9%9D%99.wav"
            },
            {
                "voice_id": "77d6d3b6-3f6d-41e6-8c42-1577a7e92402",
                "type": 10,
                "title": "温柔自然",
                "audio_url":"https://luzhuoai.tos-cn-beijing.volces.com/audio_url/%E6%B8%A9%E6%9F%94%E8%87%AA%E7%84%B6.wav"
            }
        ]
    } 

settings = Settings()
